// #include <iostream>

// using namespace std;
#include <stdio.h>
#include <stdlib.h>

//找最小的公约数
int gcd(int x, int y){
    if(x < 0 || y < 0){
        return -1;
    }
    int z = y;
    while(x % y != 0){
        z = x % y;
        x = y;
        y = z;
    }
    return z;
}

//判断过程
bool is_valid(int x, int y, int target){
    if(target % gcd(x, y) == 0){
        return true;
    }else{
        return false;
    }
}

//打印出具体的步骤
void print_r_step(int x, int y, int target){
    int inx = 0;
    int iny = 0;
    int flag = 0;

    while(true){
        if(flag++ > 999){
            //std::cout<< "fail!"<<std::endl;
            print("fail!\n");
            break;
        }
        if(inx == 0){
            //std::cout<< "fill x!"<<std::endl;
            print("fill x!\n");
            inx = x;
        }else{
            //std::cout<< "pour x into y!"<<std::endl;
            print("pour x into y!\n");
            iny += inx;
            if(iny >= y){
                inx = iny - y; //剩余的水倒入这里
                iny = 0;//清空y中的水，倒满剩余
                //std::cout<< "empty y!"<<std::endl;
                print("empty y!\n");
            }else{
                inx = 0;//不够倒满
            }
        }
        if(target == inx || target == iny){
            break;
            //std::cout<<'ok,finish!' <<std::endl;
            print("ok,finish!");
        }
    }
}

int main(int argc, char* argv){
    // int target = 20;
    // for(int i = 0; i < target; i++){
    //     if(is_valid(9, 15, target)){
    //         std::cout << target <<std::endl;
    //     }
    // }
    int x = 9;
    int y = 15;
    int target = 6;
    print_r_step(x, y, target);
    return 0;
}